﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ProyectoHCI
{
    public partial class UserVsPc : usuario
    {
        alumnoInicial Alum;
        Timer time;

        public UserVsPc()
        {
            InitializeComponent();
        }
        public UserVsPc(alumnoInicial a,Login L)
        {
            Alum = a;
            login = L;
            InitializeComponent();
        }
        //boton jugar
        private void button1_Click(object sender, EventArgs e)
        {
            Iniciar.Hide();
            rta1.Show();
            rta2.Show();
            rta3.Show();
            rta4.Show();
            pregunta.Show();
            arrancarTimer();
        }
        //el timer se usa para la barra de progreso
        private void arrancarTimer(){
            tiempo.Show();
            //timer
            time = new Timer();
            time.Interval = 250;
            time.Tick += new EventHandler(IncreaseProgressBar);
            time.Start();
        }
        //volver
        private void volver_Click(object sender, EventArgs e)
        {
            if (time != null)
            { time.Stop();
            time.Dispose();  
            }
            Alum.Show();
            this.Hide();
            this.Dispose();
        }
        //decrementar la barra
        private void IncreaseProgressBar(object sender, EventArgs e)
        {
            // Increment the value of the ProgressBar a value of one each time.
            tiempo.Increment(-1);
            // Determine if we have completed by comparing the value of the Value property to the Maximum value.
            if (tiempo.Value < (tiempo.Maximum) / 3)
                reloj.Show();
            if (tiempo.Value == tiempo.Minimum)
            {
                // Stop the timer.
                time.Stop();
                termino(0);//cero es que perdiste
            }
        }
        /**
         * El tiempo se termino o se eligio la respuesta incorrecta 
         * estado es ==0 si perdiste, 1== ganaste
         */
        private void termino(int estado)
        {
            time.Stop();
            time.Dispose();
            this.Hide();
            singlePlayer SP = new singlePlayer(login,Alum,this,estado,pregunta.Text);
            SP.Show();
            this.Dispose();
        }

        private void rta4_Click(object sender, EventArgs e)
        {
            termino(1);//ganaste
        }

        private void rta3_Click(object sender, EventArgs e)
        {
            termino(0);//perdiste
        }

        private void rta2_Click(object sender, EventArgs e)
        {
            termino(0);//perdiste
        }

        private void rta1_Click(object sender, EventArgs e)
        {
            termino(0);//perdiste
        }

       
    }
}
